package com.ykt.common.thirdapi.ry;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import io.rong.ApiHttpClient;
import io.rong.models.FormatType;
import io.rong.models.SdkHttpResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * 融云音频API帮助类
 *
 * @author long.hua
 * @version 1.0.0
 * @since 2016-01-11 22:30
 */
public class RyApiHelper {
    private final static Logger LOGGER = LoggerFactory.getLogger(RyApiHelper.class);


    private Prop prop = PropKit.use("ry.properties");
    private String url = prop.get("ry.url"); // 获取请求地址
    private String appKey = prop.get("ry.appkey");
    private String secret = prop.get("ry.secret");


    //获取token
    public String getToken(String userId, String name, String head){
        try {
            SdkHttpResult result = ApiHttpClient.getToken(appKey, secret, userId, name, head, FormatType.json);
            if(result.getHttpCode() == 200){
                return result.getResult();
            } else {
                LOGGER.info("获取融云token失败，状态码：{}", result.getHttpCode());
            }
        } catch (Exception e) {
            LOGGER.error("获取融云token失败！", e);
        }

        return null;
    }
}
